#! /bin/bash
export LANG=en_US.UTF-8
ip=`ifconfig 2>/dev/null|sed -n 2p|awk  '{ print $2 }'|awk -F : '{ print $2 }' `
ports=`netstat -lntp|grep $*|awk '{print $4}'|awk -F ':' '{print $NF}'`
http_port=
for p in $ports
do
   req_url='http://'$ip':'$p'/'
   http_code=`curl -s --connect-timeout 1 -m 1 $req_url -w%{http_code} 2>/dev/null -o /dev/null`
   if [[ "$http_code" -gt 199 ]];then
        http_port=$p
        break
   fi
done
echo $http_port